package solution.design;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author zhangmin
 * @create 2021-09-19 11:41
 */
public class DetectSquares {
    List<int[]> detectSquaresList;
    public DetectSquares() {
    detectSquaresList=new ArrayList<>();
    }

    public void add(int[] point) {
        this.detectSquaresList.add(point);
    }

    public int count(int[] point) {
        int px=point[0];
        int py=point[1];
        int[] xspoint=new int[2];
        int[] yspoint=new int[2];
        for (int[] p:detectSquaresList) {
            if (p[0]==px){
                xspoint=p;
            }else if(p[1]==py){
                yspoint=p;
            }
        }
        int xlen=xspoint[0]-px;
        int ylen=yspoint[1]-py;
        if (Math.abs(xlen)!=Math.abs(ylen))
            return 0;
        int[] lestPoint=new int[]{xspoint[1],yspoint[0]};
        if (detectSquaresList.contains(lestPoint)){
            return 1;
        }else {
            return 0;
        }
    }
}
